package yxy.game.pm2.bean.db.newDao;

import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.bean.db.po.SignPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author James
 * @date 2022/1/23 10:29
 **/
public class SignDAO {
    private static final String
            ADD_ONE = "replace into `sign` (`pCode`, `type`, `value`) values (?,?,?)",
            SELECT_BY_TYPE = "select * from `sign` where `pCode` = ? and `type` = ?",
            SELECT_ALL = "select * from `sign` where `pCode` = ?";

    public static List<SignPo> getListByType(String playerCode, int type){
        return DbManager.instance().executeQueryObjectList(SELECT_BY_TYPE, new Object[]{playerCode , type}, SignPo.builder);
    }

    public static List<SignPo> getList(String playerCode) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{playerCode}, SignPo.builder);
    }

    public static boolean replace(List<SignPo> signPoList) {
        List<Object[]> list = new ArrayList<>();
        for (SignPo signPo : signPoList) {
            Object[] objects = new Object[]{signPo.getPlayerCode(),signPo.getType(),signPo.getValue()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(ADD_ONE, list);
        return ints.length == signPoList.size();
    }
}
